{% extends 'layouts/base.html' %}
{% load static i18n status_tags %}

{% block title %}{% trans "Lista de Solicitações" %}{% endblock title %}

{% block extrastyle %}
<link rel="stylesheet" href="{% static 'css/solicitation.css' %}">
{% endblock extrastyle %}

{% block content %}
{% if messages %}
<div class="mt-3">
    {% for message in messages %}
    <div class="alert alert-{{ message.tags }}">
        {{ message }}
    </div>
    {% endfor %}
</div>
{% endif %}
<div class="container mt-4">
    <div class="header-bg p-4 rounded shadow-sm d-flex align-items-center justify-content-between">
        <div class="icon-title">
            <i class="fas fa-file-alt"></i>
            <h3 class="mb-0">{% trans "Lista de Solicitações" %}</h3>
        </div>
        <a href="{% url 'solicitation:create' %}" class="btn btn-primary">
            <i class="fas fa-plus"></i> {% trans "Criar Solicitação" %}
        </a>
    </div>

    <div class="table-responsive mt-3">
        <table class="table table-striped table-bordered">
            <thead class="table-dark">
                <tr>
                    <th>{% trans "ID" %}</th>
                    <th>{% trans "Protocolo" %}</th>
                    <th>{% trans "Situação" %}</th>
                    <th>{% trans "Data da Solicitação" %}</th>
                    <th>{% trans "Ações" %}</th>
                </tr>
            </thead>
            <tbody>
                {% for solicitation in solicitations %}
                <tr>
                    <td>{{ solicitation.id }}</td>
                    <td>{{ solicitation.protocol }}</td>
                    <td>{{ solicitation.status }}</td>
                    <td>{{ solicitation.created_at|date:"d/m/Y" }}</td>
                    <td>
                        <a href="{% url 'solicitation:solicitation_dashboard' solicitation.protocol %}" class="btn btn-primary btn_custom">
                            <i class="fas fa-eye"></i> {% trans "Ver Solicitação" %}
                        </a>
                    </td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="6" class="text-center">{% trans "Nenhuma solicitação encontrada." %}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    <nav aria-label="Page navigation" class="d-flex justify-content-center mt-3">
        <ul class="pagination">
            {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?page=1" aria-label="{% trans 'Primeira' %}">
                        <span aria-hidden="true">&laquo;&laquo;</span>
                    </a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.previous_page_number }}" aria-label="{% trans 'Anterior' %}">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            {% else %}
                <li class="page-item disabled"><span class="page-link">&laquo;&laquo;</span></li>
                <li class="page-item disabled"><span class="page-link">&laquo;</span></li>
            {% endif %}

            <li class="page-item disabled">
                <span class="page-link">{% trans "Página" %} {{ page_obj.number }} {% trans "de" %} {{ page_obj.paginator.num_pages }}</span>
            </li>

            {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.next_page_number }}" aria-label="{% trans 'Próxima' %}">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.paginator.num_pages }}" aria-label="{% trans 'Última' %}">
                        <span aria-hidden="true">&raquo;&raquo;</span>
                    </a>
                </li>
            {% else %}
                <li class="page-item disabled"><span class="page-link">&raquo;</span></li>
                <li class="page-item disabled"><span class="page-link">&raquo;&raquo;</span></li>
            {% endif %}
        </ul>
    </nav>
</div>
{% endblock content %}

{% block extra_js %}
<!-- Código JS adicional aqui, se necessário -->
{% endblock extra_js %}
